namespace ETestIT.UI.AppControls
{
    using System.Web.UI;

    public class JqMessageDialogDecorator
    {
        private readonly Page page;

        public JqMessageDialogDecorator(Page page)
        {
            this.page = page;
        }

        public string Information
        {
            set { RegisterScript("Information", value); }
        }

        public string Warning
        {
            set { RegisterScript("Warning", value); }
        }

        private void RegisterScript(string messageType, string messageText)
        {
            var jScript = @"<div    
                                id='Notification' 
                                title='@notification'
                                class='ui-corner-all'>
                                &nbsp; @Message &nbsp;
                            </div>
                            <script type='text/javascript'>
                                $(document).ready(function() {
                                    $('#Notification').fadeTo(4000, 1).fadeOut(2000);
                                });
                            </script>"
                .Replace("@notification", messageType)
                .Replace("@Message", messageText);

            if (!page.ClientScript.IsClientScriptBlockRegistered(messageType))
                page.ClientScript.RegisterClientScriptBlock(typeof(Page), messageType, jScript);
        }
    }
}